package com.ce.controller;


import com.ce.entity.Provider;
import com.ce.service.ProviderService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ce
 * @since 2022-01-02
 */
@RestController
@RequestMapping("/provider")
public class ProviderController {
    @Autowired
    ProviderService providerService;


    /**
     * 查询供应商信息
     */
    @PostMapping("/getProviderList")
    public List<Provider> testSelect(Provider provider){
        List<Provider> providers = providerService.getList(provider);
        return providers;

    }
    /**
     * 删除供应商信息
     */
    @DeleteMapping("/deleteProvider")
    public Integer deleteProvider(Integer id){
        Integer res =providerService.deleteById(id);
        return res;
    }

    /**
     * 添加供应商
     */
    @PostMapping("/addProvider")
    public Map<String, String> insertProvider(HttpServletRequest request){
        Provider provider = new Provider();
        provider.setProviderName(request.getParameter("providerName"));
        provider.setProviderPeoplename(request.getParameter("providerPeoplename"));
        provider.setProviderTel(request.getParameter("providerTel"));
        provider.setProviderAddress(request.getParameter("providerAddress"));
        provider.setProviderNote(request.getParameter("providerNote"));
        return providerService.addProvider(provider);
    }


    /**
     * 修改供应商信息
     */
    @PostMapping("/updateCustomer")
    public Map<String, String> updateCustomer(HttpServletRequest request){
        Provider provider = new Provider();
        provider.setId(Integer.parseInt(request.getParameter("id")));
        provider.setProviderName(request.getParameter("providerName"));
        provider.setProviderPeoplename(request.getParameter("providerPeoplename"));
        provider.setProviderTel(request.getParameter("providerTel"));
        provider.setProviderAddress(request.getParameter("providerAddress"));
        provider.setProviderNote(request.getParameter("providerNote"));
        return providerService.updateProvider(provider);
    }
}
